// pages/myreservation/myreservation.js
var api = require("../../utils/api.js")
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        oType: 1,
        page: 1,
        orderlist: {},
        userinfo: {},
        order_status: 1,
    },
	//订单支付
    orderdetail: function(e) {
        wx.navigateTo({
            url: '/pages/ordetails/ordetails?order_sn=' + e.currentTarget.dataset.ordersn,
        })
    },
	
    guidelines: function() {
        wx.navigateTo({
            url: '../guidelines/guidelines',
        })
    },
    cancelOrder: function(e) {
        let that = this
        wx.showModal({
            title: '友情提示',
            content: '确定取消该订单？',
            success(res) {
                if (res.confirm) {
                    let data = { order_sn: e.currentTarget.dataset.ordersn }
                    let url = app.globalData.resBaseUrl + app.u.ORDER_CANCEL
                    api.requestUrl(data, url).then(res => {
                        api.showSuccess("取消成功")
                        that.getlist()
                    })
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })

    },
    getlist: function() {
        var userinfo = wx.getStorageSync('userInfo');
        if (userinfo) {
            let data = { uid: userinfo.id, page: this.data.page, order_status: this.data.order_status }
            let url = app.globalData.resBaseUrl + app.u.ORDER_LIST
            api.requestUrl(data, url).then(res => {
                this.setData({
                    orderlist: res.data,
                    userinfo: userinfo
                })
            })
        } else {
            wx.navigateTo({
                url: '../login/login'
            })
        }
    },
    /**,
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },
    showMore: function() {
        let data = { uid: this.data.userinfo.id, page: this.data.page, order_status: this.data.order_status }
        let url = app.globalData.resBaseUrl + app.u.ORDER_LIST
        api.requestUrl(data, url).then(res => {
            this.setData({
                orderlist: this.data.orderlist.concat(res.data),
            })
        })
    },
    tableCheck: function(e) {
        var that = this;
        that.setData({
            oType: e.currentTarget.dataset.id,
            order_status: e.currentTarget.dataset.id,
            page: 1
        })
        this.getlist();
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.getlist();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        this.setData({
            page: this.data.page + 1
        })
        this.showMore();
    },

})